local skel = fk.CreateSkill {
  name = "emo__weiyi",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__weiyi"] = "唯依",
  [":emo__weiyi"] = "锁定技，①游戏开始时，你令一名其他角色获得“兄”标记。②你的手牌上限等于该角色体力值。③每当该角色造成伤害后，你摸X张牌（X为其本回合造成的伤害数之和）。",

  ["@@WYbro"] = "兄",
  ["#emo__weiyi-bro"] = "唯依：你令一名其他角色获得“兄”标记",
}

skel:addEffect(fk.GameStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      return player:getMark("emo__weiyi_bro") == 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local others = room:getOtherPlayers(player, false)
    if #others == 0 then return end
    local tos = room:askToChoosePlayers(player, { targets = others, min_num = 1, max_num = 1,
    prompt = "#emo__weiyi-bro", skill_name = skel.name, cancelable = false})
    local to = tos[1]
    room:setPlayerMark(player, "emo__weiyi_bro", to.id)
    room:addPlayerMark(to, "@@WYbro")
  end,
})

skel:addEffect(fk.Damage, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      return target and target.id == player:getMark("emo__weiyi_bro")
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = 0
    player.room.logic:getActualDamageEvents(1, function(e)
      if e.data.from == target then
        n = n + e.data.damage
      end
      return false
    end)
    if n > 0 then
      player:drawCards(n, skel.name)
    end
  end,
})

skel:addEffect("maxcards", {
  fixed_func = function(self, player)
    if player:hasSkill(skel.name) then
      local bro = Fk:currentRoom():getPlayerById(player:getMark("emo__weiyi_bro"))
      if bro and not bro.dead then
        return bro.hp
      end
    end
  end
})

skel:addLoseEffect(function (self, player, is_death)
  local bro = player.room:getPlayerById(player:getMark("emo__weiyi_bro"))
  if bro then
    player.room:removePlayerMark(bro, "@@WYbro")
  end
end)

return skel
